package Test4;

interface ABC {
    //抽象方法,没有方法体,子类必须提供具体实现
    void abstractMethod();
    //默认方法,有方法体,通过接口实例化来调用
    default void test() {};
    //静态方法,有方法体,属于接口本身,直接通过接口名调用
    static void test2(){};

    // jdk9新增,私有方法(供默认方法调用)
    private void test3(){};
    // jdk9新增,私有静态方法(供静态方法或其他私有静态方法调用)
    private static void test4(){};
}


sealed class Creature permits Animal{
    //密封类Creature只允许Animal继承
}
sealed class Animal extends Creature permits Dog,Cat{
    //密封类Animal继承制creature,并且只允许Dog和Cat继承
}
final class Dog extends Animal{
    //Dog类继承自Animal并且不能再被继承
}
non-sealed class Cat extends Animal {
    //Cat类继承制Animal并且可以被任何类继承
}

public class Test3 {
    public void process(Object input) {
        if (input instanceof String) {
            // 先检查，再手动转换
            String str = (String) input;
            System.out.println("字符串长度: " + str.length());
        } else if (input instanceof Integer) {
            // 先检查，再手动转换
            Integer num = (Integer) input;
            System.out.println("数字的平方: " + num * num);
        } else {
            System.out.println("不支持的类型");
        }
    }

    public void process2(Object input) {
        if (input instanceof String str) {
            System.out.println("字符串长度: " + str.length());
        } else if (input instanceof Integer num) {
            System.out.println("数字的平方: " + num * num);
        } else {
            System.out.println("不支持的类型");
        }
    }

    public static void main(String[] args) {



    }

    public static void main3(String[] args) {
        var a=10;
        var b="hello";
        var c=true;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);

//        var d;
    }




    enum Day {MONDAY,TUESDAY,WEDNESDAY,FRIDAY,SATURDAY,SUNDAY};
    public static void main2(String[] args) {
        Day day=Day.FRIDAY;
        String str=switch(day) {
            case MONDAY -> "The first day of the week.";
            case TUESDAY -> "The second day of the week.";
            case SATURDAY,SUNDAY ->  "Weekend.";
            default -> {
                System.out.println("FRIDAY");
                yield "The other day of the week.";
            }
        };
        System.out.println(str);
    }
    public static void main1(String[] args) {
        Day day=Day.MONDAY;
        switch(day) {
            case MONDAY:{
                System.out.println("The first day of the week.");
                break;
            }
            case TUESDAY:{
                System.out.println("The second day of the week.");
                break;
            }
            case WEDNESDAY:{
                System.out.println("The third day of the week.");
                break;
            }
            default:{
                System.out.println("The other day of the week.");
                break;
            }
        }
    }
}
